package cn.fl.customer.service.impl;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import cmm.mid.core.framework.page.Pager;
import cn.cmm.base.framework.exception.BaseException;
import cn.cmm.base.framework.utils.BaseLogUtils;
import cn.cmm.base.framework.utils.StringUtils;
import cn.fl.customer.service.ICstChkEmtRecService;
import cn.fl.customer.transform.CstChkEmtRecVOTransform;
import cn.fl.customer.vo.CstChkEmtRecVO;
import cn.fl.framework.base.context.CurrentThreadContext;
import fl.riskctrl.facade.cfca.api.IChkMpApiService;
import fl.riskctrl.facade.cfca.dto.CstChkEmtRecDTO;

/**
 * @Description:  客户端服务层接口实现
 * @Description: 业务层方法名称前缀：新增：add* 删除：remove* 修改：modify* 查询对象：select* get* 批量：batch* 查询集合：search*
 */
@Service
public class CstChkEmtRecServiceImpl implements ICstChkEmtRecService {
	
	/**
	 * 日志
	 */
	private static final Logger logger = LoggerFactory.getLogger(ICstChkEmtRecService.class);
	/**
	 *  自定义 API 暴露服务
	 */
	@Autowired
	private IChkMpApiService chkMpApiService;
	
	@Override
	public CstChkEmtRecVO selectById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "selectById", "主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		CstChkEmtRecDTO dto = chkMpApiService.getCstChkEmtRecById(id, 
				CurrentThreadContext.getFlServiceSysCd(), CurrentThreadContext.getCurrentOrgCd());
		return CstChkEmtRecVOTransform.toVO(dto);
	}

	@Override
	public Long add(CstChkEmtRecVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "add", "新增对象不能为空!", CurrentThreadContext.getCurrentUserName());
			return null;
		}
		return chkMpApiService.addCstChkEmtRec(CstChkEmtRecVOTransform.toDTO(entity));
	}

	@Override
	public boolean removeById(Long id) throws BaseException{
		if(StringUtils.isEmpty(id)){
			BaseLogUtils.info(logger, "removeById", "删除主键参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return chkMpApiService.removeCstChkEmtRec(id);
	}
	

	@Override
	public boolean modify(CstChkEmtRecVO entity) throws BaseException{
		if(null == entity){
			BaseLogUtils.info(logger, "modify", "修改对象参数不能为空!", CurrentThreadContext.getCurrentUserName());
			return false;
		}
		return chkMpApiService.modifyCstChkEmtRec(CstChkEmtRecVOTransform.toDTO(entity));
	}

	@Override
	public Pager searchListPage(Pager page) throws BaseException{
		if(null == page)page = new Pager();
		Pager pager = chkMpApiService.searchCstChkEmtRecListPage(page);
		@SuppressWarnings("unchecked")
		List<CstChkEmtRecDTO> list = (List<CstChkEmtRecDTO>) pager.getResultList();
		List<CstChkEmtRecVO> voList = CstChkEmtRecVOTransform.toVOList(list);
		pager.setResultList(voList);
		return pager;
	}
}
